package com.neuedu.nep.service.impl;

import com.neuedu.nep.dao.GridMemberDao;
import com.neuedu.nep.model.GridMember;
import com.neuedu.nep.model.GridMemberExample;
import com.neuedu.nep.service.GridMemberService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄宇佳
 * @create 2024-04-11 11:45
 * @description:
 */
@Service
public class GridMemberServiceImpl implements GridMemberService {
    @Resource
    private GridMemberDao gridMemberDao;

    @Override
    public GridMember SignIn(String gmCode, String password) {
        GridMemberExample example=new GridMemberExample();
        GridMemberExample.Criteria criteria=example.createCriteria();
        criteria.andGmCodeEqualTo(gmCode).andPasswordEqualTo(password);
        List<GridMember> gridMembers = gridMemberDao.selectByExample(example);
        if (gridMembers.size()>0){
            return gridMembers.get(0);
        }else{
            return null;
        }

    }

    @Override
    public List<GridMember> listByPidAndCid(Integer provinceId, Integer cityId) {
        GridMemberExample example=new GridMemberExample();
        GridMemberExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceIdEqualTo(provinceId);
        criteria.andCityIdEqualTo(cityId);
        criteria.andStateEqualTo(0);
        List<GridMember> gridMembers = gridMemberDao.selectByExample(example);
        if(gridMembers!=null){
            for (int i = 0; i < gridMembers.size(); i++) {
                gridMembers.get(i).setPassword(null);
            }
        }
        return gridMembers;
    }
}
